var xmlHttp;
var flagName = false, flagAge = false, flagEmail = false, flagSex = false, flagPassword = false, flagH = false, flagW = false;
function createXMLHttp() {
	try {
		xmlHttp = new XMLHttpRequest();
	} catch (e) {
		xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	}
}

function checkUsername(value) {// Ajax验证
	createXMLHttp();
	xmlHttp.open("post", "checkRegister.do?name=" + value);
	xmlHttp.send(null);
	xmlHttp.onreadystatechange = checkUsernameCallback;
	document.getElementById("name2").innerHTML = "正在验证......";
}
function checkUsernameCallback() {

	if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
		var text = xmlHttp.responseText;
		if (text == "false") {
			document.getElementById("name2").innerHTML = "×该用户已注册";
			flagName = false;
		} else if (text == "true") {
			document.getElementById("name2").innerHTML = "√可以注册";
			flagName = true;
		}
	}
}

function checkName(value) {
	if (value.match("\\w{3,15}") == null) {
		document.getElementById("name2").innerHTML = "×用户名必须是3-15位的字母或数字";
	} else {
		document.getElementById("name2").innerHTML = "√&nbsp;&bsp;&nbsp;&nbsp;";
		checkUsername(value);
	}
}
function checkAge(value) {
	if (!value.match("^[1-9]\\d+$")) {
		document.getElementById("age2").innerHTML = "×年龄必须是数字";
	} else if (value > 120) {
		document.getElementById("age2").innerHTML = "×请输入正确的年龄&nbsp;&nbsp;";
	} else {
		document.getElementById("age2").innerHTML = "√";
		flagAge = true;
	}
}
function checkEmail(email) {
	if (email.match("\\w+@\\w+\\.\\w+\\.?\\w+") == null) {
		document.getElementById("email2").innerHTML = " ×邮箱格式不正确";
	} else {
		document.getElementById("email2").innerHTML = " √"
		flagEmail = true;
	}
}

function checkSex() {
	document.getElementById("sex2").innerHTML = "√";
	flagSex = true;
}

function checkPassword() {
	var pass1 = document.getElementById("pw1").value;
	var pass2 = document.getElementById("pw2").value;
	if (pass1 != pass2) {
		document.getElementById("rpassword2").innerHTML = "两次密码不一致"
	} else if (pass1 != "") {
		flagPassword = true;
		document.getElementById("rpassword2").innerHTML = "√"
	}

}
function checkHeight(value) {
	if (value > 50 && value < 250) {
		flagH = true;
		document.getElementById("height2").innerHTML = "√";
	} else {
		document.getElementById("height2").innerHTML = "×";
	}
}
function checkWeight(value) {
	if (value > 15 && value < 250) {
		flagW = true;
		document.getElementById("weight2").innerHTML = "√";
	} else {
		document.getElementById("weight2").innerHTML = "×";
	}
}

function checkForm() {
	if (flagName && flagAge && flagSex && flagEmail && flagPassword && flagH
			&& flagW)
		return true;
	else {
		alert("信息不完整或格式错误");
		return false;
	}
}